﻿Imports System.Text

Public Class SampleWebConfigFile2008
    Public Function GetConfigFile(ByVal ConnectionStringMethod As String, ByVal ConnectionStringName As String, ByVal dtp As DataTabPage, ByVal DatabaseName As String) As String
        Dim sb As New StringBuilder

        sb.AppendLine("<?xml version=""1.0""?>")
        sb.AppendLine("")
        sb.AppendLine("<configuration>")
        sb.AppendLine("  ")
        sb.AppendLine("")
        sb.AppendLine("    <configSections>")
        sb.AppendLine("      <sectionGroup name=""system.web.extensions"" type=""System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"">")
        sb.AppendLine("        <sectionGroup name=""scripting"" type=""System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"">")
        sb.AppendLine("          <section name=""scriptResourceHandler"" type=""System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" requirePermission=""false"" allowDefinition=""MachineToApplication""/>")
        sb.AppendLine("          <sectionGroup name=""webServices"" type=""System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"">")
        sb.AppendLine("            <section name=""jsonSerialization"" type=""System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" requirePermission=""false"" allowDefinition=""Everywhere"" />")
        sb.AppendLine("            <section name=""profileService"" type=""System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" requirePermission=""false"" allowDefinition=""MachineToApplication"" />")
        sb.AppendLine("            <section name=""authenticationService"" type=""System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" requirePermission=""false"" allowDefinition=""MachineToApplication"" />")
        sb.AppendLine("            <section name=""roleService"" type=""System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" requirePermission=""false"" allowDefinition=""MachineToApplication"" />")
        sb.AppendLine("          </sectionGroup>")
        sb.AppendLine("        </sectionGroup>")
        sb.AppendLine("      </sectionGroup>")
        sb.AppendLine("    </configSections>  ")
        sb.AppendLine("")
        sb.AppendLine("")
        sb.AppendLine("    <appSettings/>")
        sb.AppendLine("    <connectionStrings>")

        If ConnectionStringMethod.ToUpper.Trim = "WEB.CONFIG CONNECTION STRINGS" Then
            Dim ConnectionString As String = ""
            If dtp.DatabaseServer.AuthenticationType = DatabaseAuthenticationType.WindowsAuthentication Then
                ConnectionString = "Database=" & DatabaseName & ";Server=" & dtp.ServerName & ";Integrated Security=SSPI;"
            Else
                ConnectionString = "Database=" & DatabaseName & ";Server=" & dtp.ServerName & ";uid=" & dtp.DatabaseServer.Login & ";PWD=" & dtp.DatabaseServer.Password & ";Connect Timeout=30;Network Library =dbmssocn"
            End If
            sb.AppendLine("        <add name=""" & ConnectionStringName & """ connectionString=""" & ConnectionString & """/>")
        End If
        sb.AppendLine("    </connectionStrings>")

        sb.AppendLine("  ")
        sb.AppendLine("    <system.web>")
        sb.AppendLine("        <!-- ")
        sb.AppendLine("            Set compilation debug=""true"" to insert debugging ")
        sb.AppendLine("            symbols into the compiled page. Because this ")
        sb.AppendLine("            affects performance, set this value to true only ")
        sb.AppendLine("            during development.")
        sb.AppendLine("")
        sb.AppendLine("            Visual Basic options:")
        sb.AppendLine("            Set strict=""true"" to disallow all data type conversions ")
        sb.AppendLine("            where data loss can occur. ")
        sb.AppendLine("            Set explicit=""true"" to force declaration of all variables.")
        sb.AppendLine("        -->")
        sb.AppendLine("        <compilation debug=""false"" strict=""false"" explicit=""true"">")
        sb.AppendLine("")
        sb.AppendLine("          <assemblies>")
        sb.AppendLine("            <add assembly=""System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089""/>")
        sb.AppendLine("            <add assembly=""System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089""/>")
        sb.AppendLine("            <add assembly=""System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("            <add assembly=""System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089""/>")
        sb.AppendLine("          </assemblies>")
        sb.AppendLine("")
        sb.AppendLine("        </compilation>")
        sb.AppendLine("        <pages>")
        sb.AppendLine("          <namespaces>")
        sb.AppendLine("            <clear />")
        sb.AppendLine("            <add namespace=""System"" />")
        sb.AppendLine("            <add namespace=""System.Collections"" />")
        sb.AppendLine("            <add namespace=""System.Collections.Generic"" />")
        sb.AppendLine("            <add namespace=""System.Collections.Specialized"" />")
        sb.AppendLine("            <add namespace=""System.Configuration"" />")
        sb.AppendLine("            <add namespace=""System.Text"" />")
        sb.AppendLine("            <add namespace=""System.Text.RegularExpressions"" />")
        sb.AppendLine("            <add namespace=""System.Linq"" />")
        sb.AppendLine("            <add namespace=""System.Xml.Linq"" />")
        sb.AppendLine("            <add namespace=""System.Web"" />")
        sb.AppendLine("            <add namespace=""System.Web.Caching"" />")
        sb.AppendLine("            <add namespace=""System.Web.SessionState"" />")
        sb.AppendLine("            <add namespace=""System.Web.Security"" />")
        sb.AppendLine("            <add namespace=""System.Web.Profile"" />")
        sb.AppendLine("            <add namespace=""System.Web.UI"" />")
        sb.AppendLine("            <add namespace=""System.Web.UI.WebControls"" />")
        sb.AppendLine("            <add namespace=""System.Web.UI.WebControls.WebParts"" />")
        sb.AppendLine("            <add namespace=""System.Web.UI.HtmlControls"" />")
        sb.AppendLine("          </namespaces>")
        sb.AppendLine("")
        sb.AppendLine("          <controls>")
        sb.AppendLine("            <add tagPrefix=""asp"" namespace=""System.Web.UI"" assembly=""System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("            <add tagPrefix=""asp"" namespace=""System.Web.UI.WebControls"" assembly=""System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("          </controls>")
        sb.AppendLine("")
        sb.AppendLine("        </pages>")
        sb.AppendLine("        <!--")
        sb.AppendLine("            The <authentication> section enables configuration ")
        sb.AppendLine("            of the security authentication mode used by ")
        sb.AppendLine("            ASP.NET to identify an incoming user. ")
        sb.AppendLine("        -->")
        sb.AppendLine("        <authentication mode=""Windows"" />")
        sb.AppendLine("        <!--")
        sb.AppendLine("            The <customErrors> section enables configuration ")
        sb.AppendLine("            of what to do if/when an unhandled error occurs ")
        sb.AppendLine("            during the execution of a request. Specifically, ")
        sb.AppendLine("            it enables developers to configure html error pages ")
        sb.AppendLine("            to be displayed in place of a error stack trace.")
        sb.AppendLine("")
        sb.AppendLine("        <customErrors mode=""RemoteOnly"" defaultRedirect=""GenericErrorPage.htm"">")
        sb.AppendLine("            <error statusCode=""403"" redirect=""NoAccess.htm"" />")
        sb.AppendLine("            <error statusCode=""404"" redirect=""FileNotFound.htm"" />")
        sb.AppendLine("        </customErrors>")
        sb.AppendLine("        -->")
        sb.AppendLine("")
        sb.AppendLine("      <httpHandlers>")
        sb.AppendLine("        <remove verb=""*"" path=""*.asmx""/>")
        sb.AppendLine("        <add verb=""*"" path=""*.asmx"" validate=""false"" type=""System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("        <add verb=""*"" path=""*_AppService.axd"" validate=""false"" type=""System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("        <add verb=""GET,HEAD"" path=""ScriptResource.axd"" type=""System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" validate=""false""/>")
        sb.AppendLine("      </httpHandlers>")
        sb.AppendLine("      <httpModules>")
        sb.AppendLine("        <add name=""ScriptModule"" type=""System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("      </httpModules>")
        sb.AppendLine("")
        sb.AppendLine("")
        sb.AppendLine("    </system.web>")
        sb.AppendLine("")
        sb.AppendLine("    <system.codedom>")
        sb.AppendLine("      <compilers>")
        sb.AppendLine("        <compiler language=""vb;vbs;visualbasic;vbscript"" extension="".vb"" warningLevel=""4""")
        sb.AppendLine("                  type=""Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"">")
        sb.AppendLine("          <providerOption name=""CompilerVersion"" value=""v3.5""/>")
        sb.AppendLine("          <providerOption name=""OptionInfer"" value=""true""/>")
        sb.AppendLine("          <providerOption name=""WarnAsError"" value=""false""/>")
        sb.AppendLine("        </compiler>")
        sb.AppendLine("      </compilers>")
        sb.AppendLine("    </system.codedom>")
        sb.AppendLine("")
        sb.AppendLine("    <!-- ")
        sb.AppendLine("        The system.webServer section is required for running ASP.NET AJAX under Internet")
        sb.AppendLine("        Information Services 7.0.  It is not necessary for previous version of IIS.")
        sb.AppendLine("    -->")
        sb.AppendLine("    <system.webServer>")
        sb.AppendLine("      <validation validateIntegratedModeConfiguration=""false""/>")
        sb.AppendLine("      <modules>")
        sb.AppendLine("        <remove name=""ScriptModule"" />")
        sb.AppendLine("        <add name=""ScriptModule"" preCondition=""managedHandler"" type=""System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("      </modules>")
        sb.AppendLine("      <handlers>")
        sb.AppendLine("        <remove name=""WebServiceHandlerFactory-Integrated""/>")
        sb.AppendLine("        <remove name=""ScriptHandlerFactory"" />")
        sb.AppendLine("        <remove name=""ScriptHandlerFactoryAppServices"" />")
        sb.AppendLine("        <remove name=""ScriptResource"" />")
        sb.AppendLine("        <add name=""ScriptHandlerFactory"" verb=""*"" path=""*.asmx"" preCondition=""integratedMode""")
        sb.AppendLine("             type=""System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("        <add name=""ScriptHandlerFactoryAppServices"" verb=""*"" path=""*_AppService.axd"" preCondition=""integratedMode""")
        sb.AppendLine("             type=""System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35""/>")
        sb.AppendLine("        <add name=""ScriptResource"" preCondition=""integratedMode"" verb=""GET,HEAD"" path=""ScriptResource.axd"" type=""System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" />")
        sb.AppendLine("      </handlers>")
        sb.AppendLine("    </system.webServer>")
        sb.AppendLine("")
        sb.AppendLine("    <runtime>")
        sb.AppendLine("      <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">")
        sb.AppendLine("        <dependentAssembly>")
        sb.AppendLine("          <assemblyIdentity name=""System.Web.Extensions"" publicKeyToken=""31bf3856ad364e35""/>")
        sb.AppendLine("          <bindingRedirect oldVersion=""1.0.0.0-1.1.0.0"" newVersion=""3.5.0.0""/>")
        sb.AppendLine("        </dependentAssembly>")
        sb.AppendLine("        <dependentAssembly>")
        sb.AppendLine("          <assemblyIdentity name=""System.Web.Extensions.Design"" publicKeyToken=""31bf3856ad364e35""/>")
        sb.AppendLine("          <bindingRedirect oldVersion=""1.0.0.0-1.1.0.0"" newVersion=""3.5.0.0""/>")
        sb.AppendLine("        </dependentAssembly>")
        sb.AppendLine("      </assemblyBinding>")
        sb.AppendLine("    </runtime>")
        sb.AppendLine("")
        sb.AppendLine("</configuration>")

        Return sb.ToString
    End Function


End Class
